<template>
  <div class="wrapper">
    <div class="search">
      <div class="search__back" @click="handelBackClick">
        <span class="iconfont">&#xe681;</span>
      </div>
      <div class="search__content">
        <span class="search__content_icon iconfont">&#xe933;</span>
        <input
          type="text"
          class="search__content__input"
          placeholder="请输入商品名称搜索"
        />
      </div>
    </div>
    <ShopInfo :item="item" :hideBorder="true" v-show="item.imgUrl" />
    <Content :shopName="item.name" />
    <Cart />
  </div>
</template>
<script>
import { reactive, toRefs } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import ShopInfo from '../../components/ShopInfo.vue'
import { get } from '../../utils/request'
import Content from './Content.vue'
import Cart from './Cart.vue'
const usehandelBackEffect = () => {
  const router = useRouter()
  const handelBackClick = () => {
    router.back()
  }
  return { handelBackClick }
}
const useShopInfoEffect = () => {
  const data = reactive({ item: {} })
  const route = useRoute()
  const { id } = route.params
  const getItemData = async () => {
    const reslut = await get(`/api/shop/${id}`)
    if (reslut?.errno === 0 && reslut?.data) {
      data.item = reslut.data
    }
  }
  const { item } = toRefs(data)
  return { getItemData, item }
}
export default {
  name: 'Shop',
  components: {
    ShopInfo,
    Content,
    Cart
  },
  setup(props) {
    const { getItemData, item } = useShopInfoEffect()
    const { handelBackClick } = usehandelBackEffect()
    getItemData()
    return { item, handelBackClick }
  }
}
</script>
<style lang="scss" scoped>
@import '../../style/common.scss';
.wrapper {
  padding: 0 0.18rem;
}
.search {
  display: flex;
  margin: 0.16rem 0rem 0.16rem 0;
  height: 0.32rem;
  line-height: 00.32rem;
  .search__back {
    height: 0.32rem;
    width: 0.3rem;
    color: #b6b6b6;
  }
  .search__content {
    flex: 1;
    background: $search-bgColor;
    border-radius: 0.16rem;
    display: flex;
    text-align: center;
    .search__content_icon {
      width: 0.44rem;
      height: 100%;
      color: $search-fontColor;
    }
    .search__content__input {
      font-size: 0.14rem;
      height: 100%;
      width: 100%;
      border: none;
      outline: none;
      background: none;
      box-sizing: border-box;
      padding-right: 0.2rem;
      color: $content-fontColor;
      &::placeholder {
        color: $content-fontColor;
      }
    }
  }
}
</style>
